<?php

class Raspored extends BaseRaspored
{
    public function getDanstring()
    {
        $dani = Functions::dani();
        return $dani[$this->getDan()];
    }

    public function save(PropelPDO $con = null)
    {
       parent::save($con);

       $razred = $this->getRazred();
       $predmets = $razred->getSmer()->getPredmets();
       $raspored_tips = DbFinder::from('Raspored')->select('Tip')->where('RazredId', $this->getRazredId())->find();

       foreach($raspored_tips as $raspored_tip)
       {
          $x = 20;
          $y = 82;
          $img = new sfImage('images/raspored/raspored.jpg', 'image/jpg', 'GD');
          $img->Text($razred, 468, 18);

          $rasporeds = DbFinder::from('Raspored')->select(array('CasP', 'Cas', 'Cas1', 'Cas2', 'Cas3', 'Cas4', 'Cas5', 'Cas6', 'Cas7', 'Cas8'))->where('RazredId', $this->getRazredId())->where('Tip', $raspored_tip)->orderBy('Dan')->find();
          foreach($rasporeds as $raspored)
          {
             foreach($raspored as $cas)
             {
               $img->Text(($cas) ? $predmets[$cas] : '', $x, ($y === 232 or $y === 292) ? $y : ($y - 3));
               $y += 30;
             }
             $y = 82;
             $x += 85;
          }

          $img->saveAs('images/raspored/'.$this->getRazredId().'_'.$raspored_tip.'.jpg');
       }
    }

}
